from rest_framework.response import Response
from system.menu.models import Menu
from utils.viewset import CustomModelViewSet
from system.menu.serializers import MenuSerializer


class MenuViewSet(CustomModelViewSet):
    """
    用户接口
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = Menu.objects.all()
    serializer_class = MenuSerializer

    def menu_list(self, request):
        queryset = Menu.objects.filter(parent__id__isnull=True).order_by('sort')
        serializer = self.get_serializer(queryset, many=True, request=request)
        data = {
            "code": 200,
            "data": serializer.data,
            "message": "",
            "success": True
        }
        return Response(data=data)
